package edu.zafu.ui.content;

import org.eclipse.jface.viewers.Viewer;
import org.eclipse.jface.viewers.ViewerSorter;

import edu.zafu.entity.Student;
import edu.zafu.score.excel.StudentDaoImpl;

public class StudentSort extends ViewerSorter {
	
	private int sortType;
	
	
	
	public StudentSort( int sortType ){
		this.sortType = sortType;
	}
	/* (non-Javadoc)
	 * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
	 */
	@Override
	public int compare(Viewer viewer, Object e1, Object e2) {
		// TODO Auto-generated method stub
		Student s1;
		Student s2;
		if( (e1 instanceof Student ) && (e2 instanceof Student )){
			s1 = (Student)e1;
			s2 = (Student)e2;
		}
		else{
			return super.compare(viewer, e1, e2);
		}
		switch (sortType){
		case StudentDaoImpl.COLUMN_STUDENT_ID:
			return s1.getId().compareTo(s2.getId());
		case StudentDaoImpl.COLUMN_STUDENT_NAME:
			return s1.getName().compareTo(s2.getName());
		case StudentDaoImpl.COLUMN_STUDENT_CLASS:
			return s1.getKlass().getName().compareTo(s2.getKlass().getName());
		case StudentDaoImpl.COLUMN_STUDENT_SEX:
			return s1.getSex().compareTo(s2.getSex());
		default:
			return super.compare(viewer, e1, e2);
		}
		
	}

	
	

	
	
}
